//
// Created by mac on 1/27/22.
//

#include <string>
using namespace std;

string addBinary(string a, string b) {
    string res = "";

    int i1 = a.length() - 1, i2 = b.length() - 1;
    int carry = 0;
    while (i1 >= 0 || i2 >= 0) {
        int x = i1 >= 0 ? a[i1] - '0' : 0;
        int y = i2 >= 0 ? b[i2] - '0' : 0;

        int sum = x + y + carry;
        res.push_back('0' + sum % 2);
        carry = sum / 2;

        i1--;
        i2--;
    }
    if (carry != 0) res.push_back('0' + carry);
    reverse(res.begin(), res.end());
    return res;

}